/**
 * Created by gongxun on 17/1/13.
 */

var NnCard = cc.Sprite.extend({
    mCardNum : null,
    mKind : null,
    mSeat : null,

    //手动拼ui
    mSpriteNum : null,
    mSpriteTagBig : null,
    mSpriteTagSmall : null,
    ctor : function(){
        this._super();
        this.setAnchorPoint(cc.p(0.5, 0.5));

        if (mo.gameHelper.developerVersion == "2.0"){
            this.mSpriteNum = new cc.Sprite();
            this.mSpriteTagBig = new cc.Sprite();
            this.mSpriteTagSmall = new cc.Sprite();

            this.addChild(this.mSpriteNum);
            this.addChild(this.mSpriteTagBig);
            this.addChild(this.mSpriteTagSmall);

            this.mSpriteNum.setAnchorPoint(cc.p(0.5, 1));
            this.mSpriteNum.setPosition(cc.p(35, 190));

            this.mSpriteTagBig.setPosition(cc.p(100, 60));

            this.mSpriteTagSmall.setScale(0.5);
            this.mSpriteTagSmall.setPosition(cc.p(35, 110));
        }
    },

    setCardNum : function(num){
        if (mo.nnCardHelper.getExistCardNum(num)){
            this.mCardNum = num;
        }else{
            this.mCardNum = 0;
        }

        if (mo.gameHelper.developerVersion == "3.0"){
            this.loadCardNumTexture();
        }else if (mo.gameHelper.developerVersion == "2.0"){
            this.loadCardTexture();
        }
    },

    loadCardNumTexture : function(){
        if (this.mCardNum == 0){
            this.setSpriteFrame("card_bg3.png");
        }else{
            this.setSpriteFrame("card_" + this.mCardNum + ".png");
        }
    },

    loadCardTexture : function(){
        if (this.mCardNum == 0){
            this.setSpriteFrame("card_bg0.png");

            this.mSpriteNum.setVisible(false);
            this.mSpriteTagBig.setVisible(false);
            this.mSpriteTagSmall.setVisible(false);

        }else{
            this.setSpriteFrame("b_bg.png");

            this.mSpriteNum.setVisible(true);
            this.mSpriteTagBig.setVisible(true);
            this.mSpriteTagSmall.setVisible(true);

            var num = this.mCardNum;
            var suit = this.getCardSuit(num);
            var tempNum = num - suit * 13 - 1;

            var suitImages = ["b_bigtag_3.png", "b_bigtag_2.png", "b_bigtag_1.png", "b_bigtag_0.png"];
            var tagBigStr = suitImages[suit];
            this.mSpriteTagBig.setSpriteFrame(tagBigStr);
            this.mSpriteTagSmall.setSpriteFrame(tagBigStr);

            //card
            var useRed = [false, true, false, true];
            var numImageStr = useRed[suit] ? "b_red_" + tempNum + ".png" : "b_black_" + tempNum + ".png";
            this.mSpriteNum.setSpriteFrame(numImageStr);
        }
    },

    getCarcJisuanNum : function(){
        var num = this.mCardNum - 1;
        var temp = num % 13;
        temp += 1;
        if (temp > 10){
            temp = 10;
        }

        //王
        if (this.mCardNum >= 53){
            temp = 10;
        }

        return temp;
    },

    //返回牌花色 0:tao 1:xin 2:mei 3:fang
    getCardSuit : function(num){
        var temp = num - 1;
        return parseInt(temp / 13);
    }
});